import request from "@/utils/request";
import type {HasSpuResponseData} from './type'

enum API{
    HASSPU_URL='/admin/product/',
    ALLTRADEMARK_URL='/admin/product/baseTrademark/getTrademarkList',
    SPUINFO='/admin/product/getSpuInfo/',
    ALLSALEATTR_URL='/admin/product/baseSaleAttrList',
    ADDSPU_URL='/admin/product/saveSpuInfo',
    UPDATESPU_URL='/admin/product/updateSpuInfo',
    ADDSKU_URL='/admin/product/saveSkuInfo',
    SKUINFO_URL='/admin/product/findBySpuId/',
    DELETESPU_URL='/admin/product/deleteSpu/'
}

export const reqHasSpu=(page,number,categoryId)=>request.get<any,HasSpuResponseData>(API.HASSPU_URL+`${page}/${number}?category3Id=${categoryId}`)

export const reqAllTradeMark=()=>request.get<any,any>(API.ALLTRADEMARK_URL)

export const reqSpuInfo = (id)=>request.get<any,any>(API.SPUINFO+id)

export const reqAllSaleAttr=()=>request.get<any,any>(API.ALLSALEATTR_URL)

export const reqAddOrUpdate = (data)=>{
    if(data.id){
        return request.post<any,any>(API.UPDATESPU_URL,data)
    }else{
        return request.post<any,any>(API.ADDSPU_URL,data)
    }
}

export const reqAddSku = (data)=>request.post<any,any>(API.ADDSKU_URL,data)

export const reqSkuList = (spuId)=>request.get(API.SKUINFO_URL+spuId)

export const reqDeleteSpu = (spuId)=>request.delete(API.DELETESPU_URL+spuId)